package school;

import java.util.LinkedList;
import java.util.List;

class Connection {
    private final int id;
    public Connection(int id) { this.id = id; }
    public int getId() { return id; }
}

public class ConnectionManager {
    private static final List<Connection> ConnectionPool = new LinkedList<>();
    private static int idGenerator = 1;

    public static synchronized Connection getAConnection() {
        if (ConnectionPool.size() < 10) {
            Connection connection = new Connection(idGenerator++);
            ConnectionPool.add(connection);
            System.out.println("已成功申请到连接对象" + connection.getId());
            return connection;
        } else System.out.println("目前没有空闲连接对象，请稍后再试！");
        return null;
    }
}
